T
CSharpTest.Net
LockFactory<T> Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Synchronization Namespace : LockFactory<T> Class

Glossary Item Box

A generic implementation that constructs a lock by type

Syntax

Visual Basic (Declaration) 
Public Class LockFactory(Of T As {New, ILockStrategy}) 
   Implements CSharpTest.Net.Interfaces.IFactory(Of ILockStrategy)ILockFactory 
C# 
public class LockFactory<T> : CSharpTest.Net.Interfaces.IFactory<ILockStrategy>ILockFactory  
where T: new(), ILockStrategy

Type Parameters

T

Example

BPlusTree/BPlusTree.Test/ThreadedBTreeTest.cs

C#Copy Code
BPlusTree<KeyInfo, DataValue>.OptionsV2 options = new BPlusTree<KeyInfo, DataValue>.OptionsV2(
    new KeyInfoSerializer(), new DataValueSerializer(), new KeyInfoComparer());
            
const int keysize = 16 + 4;
const int valuesize = keysize + 256 + 44;

options.CalcBTreeOrder(keysize, valuesize); 
options.FileName = TempFile.TempPath;
options.CreateFile = CreatePolicy.Always;
options.FileBlockSize = 8192;
options.StorageType = StorageType.Disk;
            
options.CacheKeepAliveTimeout = 10000;
options.CacheKeepAliveMinimumHistory = 0;
options.CacheKeepAliveMaximumHistory = 200;
            
options.CallLevelLock = new ReaderWriterLocking();
options.LockingFactory = new LockFactory<SimpleReadWriteLocking>();
options.LockTimeout = 10000;

using(BPlusTree<KeyInfo, DataValue> dictionary = new BPlusTree<KeyInfo, DataValue>(options))
using(WorkQueue work = new WorkQueue(Environment.ProcessorCount))
{
    Exception lastError = null;
    work.OnError += delegate(object o, ErrorEventArgs e) { lastError = e.GetException(); };

    for (int i = 0; i < Environment.ProcessorCount; i++)
        work.Enqueue(new ThreadedTest(dictionary, 1000).Run);

    Assert.IsTrue(work.Complete(true, 60000));
    Assert.IsNull(lastError, "Exception raised in worker: {0}", lastError);
}
VB.NETCopy Code
Dim options As New BPlusTree(Of KeyInfo, DataValue).OptionsV2(New KeyInfoSerializer(), New DataValueSerializer(), New KeyInfoComparer())

Const  keysize As Integer = 16 + 4
Const  valuesize As Integer = keysize + 256 + 44

options.CalcBTreeOrder(keysize, valuesize)
options.FileName = TempFile.TempPath
options.CreateFile = CreatePolicy.Always
options.FileBlockSize = 8192
options.StorageType = StorageType.Disk

options.CacheKeepAliveTimeout = 10000
options.CacheKeepAliveMinimumHistory = 0
options.CacheKeepAliveMaximumHistory = 200

options.CallLevelLock = New ReaderWriterLocking()
options.LockingFactory = New LockFactory(Of SimpleReadWriteLocking)()
options.LockTimeout = 10000

Using dictionary As New BPlusTree(Of KeyInfo, DataValue)(options)
    Using work As New WorkQueue(Environment.ProcessorCount)
        Dim lastError As Exception = Nothing
        work.OnError += Function(o As Object, e As ErrorEventArgs) Do
            lastError = e.GetException()
        End Function

        Dim i As Integer = 0
        While i < Environment.ProcessorCount
            work.Enqueue(New ThreadedTest(dictionary, 1000).Run)
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While

        Assert.IsTrue(work.Complete(True, 60000))
        Assert.IsNull(lastError, "Exception raised in worker: {0}", lastError)
    End Using
End Using

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Synchronization.LockFactory<T>

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys